package com.athuiju.hr.mapper;

import com.athuiju.hr.entity.Profiles;
import com.athuiju.hr.entity.vo.ProRessultVo;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;

import com.baomidou.mybatisplus.core.toolkit.Constants;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;



import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author wzh
 * @since 2021-12-15
 */
@Repository
public interface ProfilesMapper extends BaseMapper<Profiles> {
    /*在职分页*/
    IPage<ProRessultVo>selectMyPage(IPage<ProRessultVo> page, @Param(Constants.WRAPPER) Wrapper<ProRessultVo> querywrapper);

    /*根据id查询人员信息*/
    @Select("SELECT\n" +
            "\t`profiles`.id,\n" +
            "\t`profiles`.`name`,\n" +
            "\t`profiles`.age,\n" +
            "\t`profiles`.card_id,\n" +
            "\t`profiles`.address,\n" +
            "\t`profiles`.residence,\n" +
            "\t`profiles`.number,\n" +
            "\t`profiles`.email,\n" +
            "\t`profiles`.name_is,\n" +
            "\t`profiles`.number_is,\n" +
            "\t`profiles`.play_card,\n" +
            "\t`profiles`.zhifubao,\n" +
            "\t`profiles`.postid,\n" +
            "\t`profiles`.gradesid,\n" +
            "\t`profiles`.sectorid,\n" +
            "\t`profiles`.organizationid,\n" +
            "\t`profiles`.gmt_create,\n" +
            "\t`profiles`.gmt_modified,\n" +
            "\t`profiles`.rtf,\n" +
            "\tposition.post,\n" +
            "\tgrades.grades,\n" +
            "\tsector.sector,\n" +
            "\torganization.organization,\n" +
            "\t`profiles`.sex,\n" +
            "\t`profiles`.gmt_departure,\n" +
            "\t`profiles`.gmt_positive,\n" +
            "\t`profiles`.gmt_board \n" +
            "FROM\n" +
            "\tposition\n" +
            "\tINNER JOIN `profiles` ON position.postid = `profiles`.postid\n" +
            "\tINNER JOIN grades ON grades.gradesid = `profiles`.gradesid\n" +
            "\tINNER JOIN sector ON `profiles`.sectorid = sector.sectorid\n" +
            "\tINNER JOIN organization ON organization.organizationid = `profiles`.organizationid \n" +
            "\tAND `profiles`.is_deleted = 0 where `profiles`.id=#{id}")
    List<ProRessultVo> getByid(Integer id);


   /* 离职分页*/
    IPage<ProRessultVo>selectMyPageDimission(IPage<ProRessultVo> page, @Param(Constants.WRAPPER) Wrapper<ProRessultVo> querywrapper);

    /*离职人数*/
   @Select("SELECT COUNT(*)  FROM `profiles` WHERE date_format(gmt_departure,'%Y-%m') = date_format(now(),'%Y-%m') AND `profiles`.gmt_departure IS NOT NULL AND `profiles`.is_deleted=0")
    Integer countPro();

      /*入职人数*/
     @Select("SELECT COUNT(*)  FROM `profiles` WHERE date_format(gmt_board,'%Y-%m') = date_format(now(),'%Y-%m') AND `profiles`.gmt_departure IS  NULL AND `profiles`.is_deleted=0")
    Integer countFalse();


     @Select("SELECT * FROM `profiles` where  is_deleted=0")
     List<Profiles> getProId();

     @Select("SELECT COUNT(*)  FROM `profiles` WHERE `profiles`.is_deleted=0 AND `profiles`.gmt_departure IS  NULL")
    Integer countFalsePro();

     @Select("SELECT COUNT(*)  FROM `profiles` WHERE  `profiles`.gmt_departure IS NOT NULL AND `profiles`.is_deleted=0")
    Integer countProSum();
}
